package com.zz.service;

import com.zz.domain.HeartbeatLog;
import com.zz.domain.StudentMachine;
import com.zz.mapper.HeartbeatLogMapper;
import com.zz.mapper.StudentMachineMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class HeartbeatService {
    @Autowired
    private HeartbeatLogMapper heartbeatLogMapper;

    @Autowired
    private StudentMachineMapper studentMachineMapper;

    @Autowired
    private StudentMachineService studentMachineService;

    public String handleHeartbeat(String machineId) {
        Date now = new Date();
        // 记录心跳日志
        HeartbeatLog log = new HeartbeatLog();
        log.setMachineId(machineId);          // 客户端机器ID
        log.setHeartbeatTime(now);            // 心跳到达时间
        log.setResponseTime(now);             // 服务端响应时间
        log.setResponseStatus("pong");        // 固定响应值
        heartbeatLogMapper.insert(log);       // 写入数据库
        return "pong";
    }
}